//
//  Container.swift
//  AICleaner
//
//  Created by firefly on 2025/1/26.
//

import SwiftUI

struct Container<Content: View>: View {
    var alignment: Alignment = .center
    var padding: EdgeInsets = .init(top: 0, leading: 0, bottom: 0, trailing: 0)
    var margin: EdgeInsets = .init(top: 0, leading: 0, bottom: 0, trailing: 0)
    var backgroundColor: Color = .clear
    var cornerRadius: CGFloat = 0
    var border: (color: Color, width: CGFloat)? = nil
    var shadow: (color: Color, radius: CGFloat, x: CGFloat, y: CGFloat)? = nil
    var width: CGFloat? = nil
    var height: CGFloat? = nil
    var gradient: LinearGradient? = nil
    var onTap: (() -> Void)? = nil
    var content: () -> Content
    
    var body: some View {
        VStack(alignment: alignment.horizontal) {
            content()
        }
        .padding(padding)
        .frame(width: width, height: height, alignment: alignment)
        .background(
            ZStack {
                if let gradient = gradient {
                    gradient
                } else {
                    backgroundColor
                }
                if let border = border {
                    RoundedRectangle(cornerRadius: cornerRadius)
                        .stroke(border.color, lineWidth: border.width)
                }
            }
        )
        .cornerRadius(cornerRadius)
        .shadow(
            color: shadow?.color ?? .clear,
            radius: shadow?.radius ?? 0,
            x: shadow?.x ?? 0,
            y: shadow?.y ?? 0
        )
        .padding(margin)
        .onTapGesture {
            onTap?()
        }
    }
}
